package org.jeecg.modules.workflow.controller.definition;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.workflow.vo.definition.process.BpmProcessDefinitionListReqVO;
import org.jeecg.common.workflow.vo.definition.process.BpmProcessDefinitionPageItemRespVO;
import org.jeecg.common.workflow.vo.definition.process.BpmProcessDefinitionPageReqVO;
import org.jeecg.common.workflow.vo.definition.process.BpmProcessDefinitionRespVO;
import org.jeecg.modules.workflow.controller.BaseController;
import org.jeecg.modules.workflow.service.definition.BpmProcessDefinitionService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Api(tags = "管理后台 - 流程定义")
@RestController
@RequestMapping("/bpm/process-definition")
@Validated
public class BpmProcessDefinitionController extends BaseController {

    @Resource
    private BpmProcessDefinitionService bpmDefinitionService;

    @GetMapping("/page")
    @ApiOperation(value = "获得流程定义分页")
    //@RequiresPermissions("bpm:process-definition:query")
    public Result<IPage<BpmProcessDefinitionPageItemRespVO>> getProcessDefinitionPage(
            BpmProcessDefinitionPageReqVO pageReqVO) {
        IPage<BpmProcessDefinitionPageItemRespVO> pageResult = bpmDefinitionService.getProcessDefinitionPage(pageReqVO);
        return Result.OK(pageResult);
    }

    @GetMapping("/list")
    @ApiOperation(value = "获得流程定义列表")
    //@RequiresPermissions("bpm:process-definition:query")
    public Result<List<BpmProcessDefinitionRespVO>> getProcessDefinitionList(
            BpmProcessDefinitionListReqVO listReqVO) {
        return Result.OK(bpmDefinitionService.getProcessDefinitionList(listReqVO));
    }

    @GetMapping("/get-bpmn-xml")
    @ApiOperation(value = "获得流程定义的 BPMN XML")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
    //@RequiresPermissions("bpm:process-definition:query")
    public Result<String> getProcessDefinitionBpmnXML(@RequestParam("id") String id) {
        String bpmnXML = bpmDefinitionService.getProcessDefinitionBpmnXML(id);
        return Result.OK("",bpmnXML);
    }

    @GetMapping("/list/map")
    @ApiOperation(value = "获得分类流程定义列表")
    //@RequiresPermissions("bpm:process-definition:query")
    public Result<Map<String,List<BpmProcessDefinitionRespVO>>> getProcessDefinitionListMap(
            BpmProcessDefinitionListReqVO listReqVO) {
        return Result.OK(bpmDefinitionService.getProcessDefinitionListMap(listReqVO));
    }
}
